package com.ymatou.iapi.invoice.query.testcase;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.invoice.query.service.MonthTradeCheckDailyBillListGetCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AssertService;
import com.ymttest.database.model.YmtTradeCheck;
import com.ymttest.database.sqlwapper.YmtAWAccountWapper;
import com.ymttest.database.sqlwapper.YmtTradeCheckWapper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;
/**
*查询月账单K线图
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MonthTradeCheckDailyBillListGet{
	private static MonthTradeCheckDailyBillListGetCall monthtradecheckdailybilllistgetCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询月账单K线图");
	}

	@Before
	public void caseUp() {
		monthtradecheckdailybilllistgetCall=new MonthTradeCheckDailyBillListGetCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(monthtradecheckdailybilllistgetCall.getOpurl());
	}

	public static void  monthtradecheckgetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
		    String dataStr = monthtradecheckdailybilllistgetCall.getReturnData();
			//返回报文断言			

			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    } 
	}
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_MonthTradeCheckDailyBillListGet_001() {
		Logger.start(true,"查询月账单K线图");
		try {
			//TODO 补全case代码
			//调用接口
		    Map<String, Object> getMap = new HashMap<String,Object>();			
			JSONObject result=monthtradecheckdailybilllistgetCall.callAndGetReturnData(getMap);
			
			//获取返回的报文
			Logger.verifyNotNull(result, "返回报文非空");
			//断言报文返回true
			String success= result.getString("Success");
			Logger.verifyIsContains(true, success, "\"Success\":true");
			//断言errorMsg为空
			String errMsg=result.getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "ErrorMsg等于空");
			
			if(errMsg=="null")
			{
				//SQL ymtfp库  Ymt_AWTradeCheck
				//获得数据库查询出的数据
				YmtTradeCheckWapper ymtTradeCheckWapper=new YmtTradeCheckWapper();
				List<YmtTradeCheck> basedailybillList = ymtTradeCheckWapper.selectBySellerId(3383, YMTDateUtil.parseYMDHMSDate("2016-10-01 00:00:00"), YMTDateUtil.parseYMDHMSDate("2016-10-31 23:59:59"));
				YmtTradeCheck basedailybill = basedailybillList.get(0);
				
				//数组格式的返回报文
				JSONArray TradeCheckBillDailyInfoList = result.getJSONArray("TradeCheckBillDailyInfoList");
				//断言报文返回的数量跟数据库查询出的数量相等
				int a= TradeCheckBillDailyInfoList.length();
				int b= basedailybillList.size();
				Logger.verifyEquals(a, b, "报文返回个数于数据库查询个数相等");		
				
				//判断返回的月账单中每日数据相同
				if(a>0)
				{
					//获得返回报文的第一条数据
					JSONObject checkBillCode = TradeCheckBillDailyInfoList.getJSONObject(0);
					//转化为Map
					Map<String, Object> basedailybillforMap= MapUtil.pojoToMap(basedailybill);
					//建立映射关系
					Map<String, String> tacmap = new HashMap<String, String>();
					tacmap.put("sCheckBillCode", "CheckBillCode");
					tacmap.put("fIncomeAmt","IncomeAmt");
					tacmap.put("fExpenditureAmt","ExpenditureAmt");	
					//检查数据一致性
					AssertService.assertResultEqual(tacmap, basedailybillforMap,checkBillCode);
					
					
					
				}
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_MonthTradeCheckDailyBillListGet_002() {
		Logger.start(false,"月账单不存在");
		try {
			Map<String, Object> updateMap = new HashMap<String,Object>();
			//更改报文，传入当天的日期
			updateMap.put("TradeDate", YMTDateUtil.getFormatTime(YMTDateUtil.getDate(),"yyyy-MM-dd"));
			JSONObject result=monthtradecheckdailybilllistgetCall.callAndGetReturnData(updateMap);
			
			String errCode=result.getString("ErrCode");
			monthtradecheckgetreturnerrcode("1101","月账单不存在");
						
		}
		catch (Exception e) {
			Logger.fail(e);
		}
}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_MonthTradeCheckDailyBillListGet_003() {
		Logger.start(false,"账单日期为空");
		try {
			Map<String, Object> updateMap = new HashMap<String,Object>();
			//更改报文，传入当天的日期
			updateMap.put("TradeDate", null);
			JSONObject result=monthtradecheckdailybilllistgetCall.callAndGetReturnData(updateMap);
			
			String errCode=result.getString("ErrCode");
			monthtradecheckgetreturnerrcode("1002","请输入的账单日期");
						
		}
		catch (Exception e) {
			Logger.fail(e);
		}
}
	
}

